<section class="metadata-prompt">
  <header class="metadata-prompt__header">
    <p>
      {{if isEditing
           "Does any field in the schema contain an IDs (e.g. Member ID, Enterprise Profile ID etc) or other PII information?"
           "IDs and PII in the schema"}}

      {{more-info
        link="http://go/gdpr-pii"
        tooltip="Click for more information on Schema field format and types"
      }}

    </p>
  </header>
</section>

<section class="compliance-entities-meta">
  {{ember-selector
    values=fieldReviewOptions
    selected=(readonly fieldReviewOption)
    selectionDidChange=(action "onFieldReviewChange")
  }}

  {{#if changeSetReviewCount}}
    <span class="dataset-compliance-fields__has-suggestions">
          {{changeSetReviewCount}} fields to be reviewed
    </span>
  {{/if}}
</section>

{{#if foldedChangeSet.length}}
  {{#dataset-table
    class="dataset-compliance-fields"
    fields=foldedChangeSet
    filterBy=filterBy
    tableRowComponent='dataset-compliance-rollup-row'
    searchTerm=searchTerm as |table|
  }}

    {{#table.head as |head|}}
      {{#head.column class="dataset-compliance-fields__notification-column"}}{{/head.column}}
      {{#head.column class="dataset-compliance-fields__identifier-column"}}
        Field

        {{more-info
          link="http://go/tms-schema"
          tooltip="Click for more information on Schema"
        }}
      {{/head.column}}
      {{#head.column class="nacho-table-cell-wrapped"}}
        System Suggestion & Confidence
      {{/head.column}}
      {{#head.column class="nacho-table-cell-wrapped"}}Compliance Information{{/head.column}}
      {{#head.column class="dataset-compliance-fields__notification-column"}}{{/head.column}}
    {{/table.head}}

    <tr>
      <th>{{!--spacer--}}</th>
      <th colspan="4">
        <div class="dataset-compliance-fields__actions">
          {{disable-bubble-input
            title="Search field names"
            placeholder="Search field names"
            value=table.searchTerm
            class="dataset-compliance-fields__search"
            on-input=(action table.filterDidChange value="target.value")
          }}
        </div>
      </th>
    </tr>

    {{#table.body as |body|}}
      {{#each table.data as |field|}}
        {{#body.row
          field=field
          isNewComplianceInfo=isNewComplianceInfo
          complianceDataTypes=complianceDataTypes
          onFieldDblClick=(action "onFieldDblClick")
          onFieldTagAdded=(action "onFieldTagAdded")
          onFieldTagRemoved=(action "onFieldTagRemoved")
          onTagIdentifierTypeChange=(action "tagIdentifierChanged")
          onSuggestionIntent=(action "onFieldSuggestionIntentChange") as |row|
        }}
          <tr class="{{if row.isReadonly 'dataset-compliance-fields--readonly'}}" ondblclick={{action row.onFragmentDblClick}}>
            {{#row.cell}}
              {{#if row.isReadonly}}

                <i class="fa fa-lock dataset-compliance-fields--readonly__icon" title="Readonly">
                  {{tooltip-on-element
                    text="Readonly"
                  }}
                </i>

              {{else}}
                {{#if
                  (and row.suggestion (and (not row.suggestionMatchesCurrentValue) (not row.suggestionResolution)))}}

                  <i class="fa fa-exclamation dataset-compliance-fields__has-suggestions__icon"
                     title="Compliance field has suggested values">
                    {{tooltip-on-element
                      text="Has suggestions"
                    }}
                  </i>

                {{else}}

                  {{#if row.isReviewRequested}}

                    <i class="fa fa-question dataset-compliance-fields--review-required__icon"
                       title="Compliance policy information needs review">
                      {{tooltip-on-element
                        text="Please review"
                      }}
                    </i>

                  {{else}}

                    <i class="fa fa-check dataset-compliance-fields--ok__icon" title="All good!">
                      {{tooltip-on-element
                        text="All good!"
                      }}
                    </i>


                  {{/if}}

                {{/if}}
              {{/if}}
            {{/row.cell}}

            {{#row.cell}}
              <div class="dataset-compliance-fields__id-field-wrap">
                {{#if isReadOnly}}
                  <div class="dataset-compliance-fields__id-field-wrap__edit">

                    <button
                      class="nacho-button nacho-button--tertiary dataset-compliance-fields__rollup-toggle"
                      onclick={{action row.onEditPolicy (action "nextStep")}}>

                      {{tooltip-on-element text="Edit Policy"}}
                      <i class="fa fa-pencil" aria-label="Edit Policy"></i>

                    </button>

                  </div>
                {{/if}}

                <div class="dataset-compliance-fields__id-field-wrap__prop">
                  <div title="{{row.identifierField}}">
                    <strong>
                      {{if isShowingFullFieldNames row.identifierField (split-text row.identifierField 23)}}
                    </strong>
                  </div>

                  <div title="{{row.dataType}}">
                    {{if isShowingFullFieldNames row.dataType (split-text row.dataType 23)}}
                  </div>
                </div>
              </div>
            {{/row.cell}}

            {{#row.cell}}
              <div class="dataset-compliance-fields__suggested-values">
                {{#if row.suggestion}}
                  <span class="dataset-compliance-fields__suggested-value {{unless row.suggestionResolution
                                                                                   'dataset-compliance-fields__suggested-value--no-res'}}">
                    {{row.suggestion.identifierType}}
                  </span>

                  <span class="dataset-compliance-fields__suggested-value {{unless row.suggestionResolution
                                                                                   'dataset-compliance-fields__suggested-value--no-res'}}">
                    {{row.suggestion.logicalType}}
                  </span>

                  {{row.suggestion.confidence}}%
                  &nbsp;
                  {{#if isEditing}}
                    {{#if row.suggestionResolution}}
                      <div class="dataset-compliance-fields__resolution {{if (eq row.suggestionResolution 'Accepted')
                                                                             'dataset-compliance-fields__resolution--ok'}}">
                        {{row.suggestionResolution}}
                      </div>
                    {{else}}

                      {{auto-suggest-action
                        type="accept"
                        field=row.fieldProps
                        feedbackAction=(action notifyOnComplianceSuggestionFeedback)
                        onSuggestionClick=(action row.onSuggestionClick)
                      }}

                      {{auto-suggest-action
                        field=row.fieldProps
                        feedbackAction=(action notifyOnComplianceSuggestionFeedback)
                        onSuggestionClick=(action row.onSuggestionClick)
                      }}

                    {{/if}}
                  {{/if}}
                {{else}}
                  &mdash;
                {{/if}}
              </div>
            {{/row.cell}}

            {{#row.cell}}
              {{#if (and isEditing (and (not row.isReadonly) (not row.hasNoneTag)))}}
                <button
                  class="nacho-button nacho-button--tertiary dataset-compliance-fields__add-field"
                  onclick={{action row.onAddFieldTag}}>
                  + Add Field Tag
                </button>
              {{else}}
                {{#each row.fieldChangeSet as |tag|}}
                  <div>
                    {{tag.identifierType}}
                  </div>
                {{/each}}
              {{/if}}
            {{/row.cell}}

            {{#row.cell}}
              <button
                class="nacho-button nacho-button--tertiary dataset-compliance-fields__rollup-toggle"
                onclick={{action row.onToggleRowExpansion}}>
                {{tooltip-on-element text=(if row.isRowExpanded "Collapse field" "Expand field")}}

                {{#if row.isRowExpanded}}
                  <i class="glyphicon glyphicon-menu-up" aria-label="Expand field"></i>
                {{else}}
                  <i class="glyphicon glyphicon-menu-down" aria-label="Collapse field"></i>
                {{/if}}

              </button>
            {{/row.cell}}
          </tr>

          {{#if row.isRowExpanded}}
            {{#each row.fieldChangeSet as |tag|}}
              {{#dataset-compliance-field-tag
                class="dataset-compliance-fields__tag-row"
                tag=tag
                parentHasSingleTag=row.hasSingleTag
                fieldIdentifiers=row.taggedIdentifiers
                onTagIdentifierTypeChange=(action "tagIdentifierChanged")
                onTagLogicalTypeChange=(action "tagLogicalTypeChanged")
                onTagOwnerChange=(action "tagOwnerChanged")
                complianceFieldIdDropdownOptions=complianceFieldIdDropdownOptions
                complianceDataTypes=complianceDataTypes as |tagRowComponent|
              }}

                {{#row.cell}}
                {{!--spacer--}}
                {{/row.cell}}

                {{#row.cell class="dataset-compliance-fields__identifier-cell"}}
                  <div class="dataset-compliance-fields__identifier-select">
                    {{ember-selector
                      disabled=(or (not isEditing) row.isReadonly)
                      values=tagRowComponent.fieldIdDropDownOptions
                      selected=(readonly tag.identifierType)
                      selectionDidChange=(action tagRowComponent.tagIdentifierTypeDidChange)
                      class=(if (and row.hasNoneTag (not-eq tag.identifierType ComplianceFieldIdValue.None)) "dataset-compliance-fields--missing-selection")
                    }}
                  </div>
                {{/row.cell}}

                <td colspan="2">
                  <div class="dataset-compliance-fields__tag-options">
                    {{#if tagRowComponent.isIdType}}
                      <label for="{{concat tagRowComponent.rowId '-compliance-field-logical-type'}}"
                             class="dataset-compliance-fields__tag-label">
                        Field Format:
                      </label>

                      <div class="dataset-compliance-fields__select-wrapper">
                        {{ember-selector
                          id=(concat tagRowComponent.rowId "-compliance-field-logical-type")
                          disabled=(or (not isEditing) row.isReadonly)
                          values=tagRowComponent.fieldFormats
                          selected=(readonly tag.logicalType)
                          selectionDidChange=(action tagRowComponent.tagLogicalTypeDidChange)
                          class=(if tagRowComponent.isTagFormatMissing "dataset-compliance-fields--missing-selection")
                        }}
                      </div>

                      {{#unless tagRowComponent.isTagFormatMissing}}
                        <span class="dataset-compliance-fields__tag-label">
                          Owner:

                          {{more-info
                            link="http://go/compliance-owner"
                            tooltip="Click for more information on Compliance owner"
                          }}
                        </span>

                        {{input
                          id=(concat tagRowComponent.rowId "-compliance-field-owner-toggle")
                          type="checkbox"
                          class="toggle-switch toggle-switch--light"
                          disabled=(or (not isEditing) row.isReadonly)
                          checked=(readonly (eq tag.nonOwner false))
                          change=(action tagRowComponent.tagOwnerDidChange value="target.checked")
                        }}
                        <label for="{{concat tagRowComponent.rowId '-compliance-field-owner-toggle'}}"
                               class="toggle-button"></label>

                      {{/unless}}
                    {{else}}

                    {{/if}}
                  </div>
                </td>

                {{#row.cell}}
                  {{#if (and isEditing (not row.hasSingleTag))}}
                    <button class="nacho-button nacho-button--tertiary dataset-compliance-fields__remove-tag"
                            onclick={{action row.onRemoveFieldTag tag}}>
                      &times;
                    </button>
                  {{/if}}
                {{/row.cell}}
              {{/dataset-compliance-field-tag}}
            {{/each}}
          {{/if}}

        {{/body.row}}
      {{/each}}
    {{/table.body}}

  {{/dataset-table}}

{{else}}

  {{empty-state
    heading="No fields found"
    subHead="If you have a filter applied, setting this to the least restrictive option may yield more results."
  }}

{{/if}}
